package com.atguigu.lease.web.admin.controller;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.CityInfo;
import com.atguigu.lease.model.entity.DistrictInfo;
import com.atguigu.lease.model.entity.ProvinceInfo;
import com.atguigu.lease.web.admin.service.CityService;
import com.atguigu.lease.web.admin.service.DistrictService;
import com.atguigu.lease.web.admin.service.ProvinceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 李壮
 * @CreateTime: 2025-05-07
 * @Version: 1.0
 */


@RestController
@RequestMapping("/admin/region")
@Tag(name = "地区信息管理")
public class RegionController {

    @Autowired
    ProvinceService provinceService;

    @Autowired
    DistrictService districtService;

    @Autowired
    CityService cityService;

    @Operation(summary = "查询省份信息列表")
    @GetMapping("/province/list")
    public Result list(){
        List<ProvinceInfo> list = provinceService.list();
        return Result.ok(list);
    }

    @Operation(summary = "根据城市id查询区县信息")
    @GetMapping("/district/listByCityId")
    public Result listByCityId(@RequestParam Long cityId){

        LambdaQueryWrapper<CityInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CityInfo::getProvinceId,cityId);
        List<CityInfo> cityInfoList = cityService.list(lambdaQueryWrapper);
        return Result.ok(cityInfoList);
    }

    @Operation(summary = "根据省份id查询城市信息列表")
    @GetMapping("/city/listByProvinceId")
    public Result listByProvinceId(@RequestParam Long provinceId){

        LambdaQueryWrapper<DistrictInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DistrictInfo::getCityId,provinceId);
        List<DistrictInfo> districtInfoList = districtService.list(lambdaQueryWrapper);
        return Result.ok(districtInfoList);
    }


}
